package com.cg.controller;

import com.cg.client.UserClient;
import com.cg.dto.Dto;
import com.cg.vo.LoginUserVo;
import com.cg.vo.TokenVO;
import com.cg.vo.UpdateUserVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/v")
public class TokenController {

    @Resource
    private UserClient userClient;

    //根据Token获取用户信息
    //@PostMapping("/queryUserInfoByToken")
    @PostMapping("/loadCurrentUserByToken")
    public Dto findUserByToken(HttpServletRequest request){
        String token = request.getHeader("token");
        return userClient.findUserByToken(token);
    }


    //刷新Token
    @PostMapping("/replaceToken")
    public Dto<TokenVO> replaceToken(HttpServletRequest request){
        String token = request.getHeader("token");
        return userClient.replaceToken(token);
    }


    //个人信息获取
    //根据token获取个人信息
    @PostMapping("/queryUserInfoByToken")
    public Dto<LoginUserVo> queryUserInfoByToken(HttpServletRequest request){
        String token = request.getHeader("token");
        return userClient.queryUserInfoByToken(token);
    }


    //用户信息修改---无头像修改
    @PostMapping("/modifyUserInfo")
    public Dto updateUser(HttpServletRequest request,@RequestBody UpdateUserVo updateUserVo){
        String token = request.getHeader("token");
        updateUserVo.setToken(token);
        return userClient.updateUser(updateUserVo);
    }
}
